From 40bbc19351b913fc442c67c16add7dbeac37baa7 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Mon, 8 Jan 2007 22:04:32 +0000 Subject: [PATCH] Only check for valid timestamps if really needed. Based on patch from Vladimir Kondratiev. --- trackfilter.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/trackfilter.c b/trackfilter.c index 1dde8ddf3..6b209b8cd 100644 --- a/trackfilter.c +++ b/trackfilter.c @@ -2,7 +2,7 @@ Track manipulation filter - Copyright (C) 2005 Olaf Klein, o.b.klein@gpsbabel.org + Copyright (C) 2005-2006 Olaf Klein, o.b.klein@gpsbabel.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,11 +25,13 @@ 2005-07-26: implemented move option 2005-07-26: implemented merge option 2005-07-29: warning fixes - 2005-08-01: Add 'static' qualifier when we can (RJL) - 2005-10-04: Add filterdefs to hold protos for filter functions... (RJL) + 2005-08-01: Add 'static' qualifier when we can (robertl) + 2005-10-04: Add filterdefs to hold protos for filter functions... (robertl) 2005-10-04: Fix range-check max. value; exit filter, if no more tracks left - 2006-04-06: Add fix, course, and speed options + 2006-04-06: Add fix, course, and speed options (parkrrrr) 2006-06-01: Add name option + 2007-01-08: if not really needed disable check for valid timestamps + (based on patch from Vladimir Kondratiev) */ #include @@ -119,6 +121,7 @@ static int track_ct = 0; static int track_pts = 0; static int opt_interval = 0; static int opt_distance = 0; +static char need_time; /* initialized within trackfilter_init */ /******************************************************************************* * helpers @@ -251,8 +254,8 @@ trackfilter_fill_track_list_cb(const route_head *track) /* callback for track_d track_pts++; wpt = (waypoint *)elem; - if (wpt->creation_time == 0) - fatal(MYNAME "-init: Found track point without time!\n"); + is_fatal((need_time != 0) && (wpt->creation_time == 0), + MYNAME "-init: Found track point without time!"); i++; if (i == 1) @@ -261,7 +264,7 @@ trackfilter_fill_track_list_cb(const route_head *track) /* callback for track_d if (i == track->rte_waypt_ct) track_list[track_ct].last_time = wpt->creation_time; - if ((prev != NULL) && (prev->creation_time > wpt->creation_time)) + if ((need_time != 0) && (prev != NULL) && (prev->creation_time > wpt->creation_time)) { if (opt_merge == NULL) fatal(MYNAME "-init: Track points badly ordered (timestamp)!\n"); @@ -847,6 +850,21 @@ trackfilter_init(const char *args) int count = track_count(); +/* + * check time presence only if required. Options that NOT require time: + * + * - opt_title (!!! only if no format specifier is present !!!) + * - opt_course + * - opt_name + */ + need_time = ( + opt_merge || opt_pack || opt_split || opt_sdistance || + opt_move || opt_start || opt_stop || opt_fix || opt_speed || + (trackfilter_opt_count() == 0) /* do pack by default */ + ); + /* in case of a formated title we also need valid timestamps */ + if ((opt_title != NULL) && (strchr(opt_title, '%') != NULL)) need_time = 1; + track_ct = 0; track_pts = 0; @@ -857,7 +875,8 @@ trackfilter_init(const char *args) /* check all tracks for time and order (except merging) */ track_disp_all(trackfilter_fill_track_list_cb, NULL, NULL); - qsort(track_list, track_ct, sizeof(*track_list), trackfilter_init_qsort_cb); + if (need_time) + qsort(track_list, track_ct, sizeof(*track_list), trackfilter_init_qsort_cb); } } -- 2.30.2